package com.example.jacky.android_easeui.demo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

import com.example.jacky.android_easeui.R;
import com.example.jacky.uilibrary.view.MyScrollView;


public class ImItateViewPagerActivity extends Activity {
    public static final String TAG = "ImItateViewPagerActivity";

    private MyScrollView msv;
    private RadioGroup radioGroup;
    //图片资源ID 数组
    private int[] ids = new int[]{R.drawable.a1, R.drawable.a2
            , R.drawable.a3, R.drawable.a4, R.drawable.a5, R.drawable.a6};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_imitateviewpager);

        msv = (MyScrollView) findViewById(R.id.myscroll_view);
        radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
        for (int i = 0; i < ids.length; i++) {
            ImageView iv = new ImageView(this);
            iv.setBackgroundResource(ids[i]);
            msv.addView(iv);

        }

        /**
         * scrollview展示复杂的view
         */
        View temp = View.inflate(this, R.layout.layout_complex_imitateviewpager, null);
        msv.addView(temp);
        for (int i = 0; i < msv.getChildCount(); i++) {
            RadioButton rbt = new RadioButton(this);
            rbt.setId(i);
            radioGroup.addView(rbt);
            if (i == 0) {
                rbt.setChecked(true);
            }
        }

        msv.setPageChangedListener(new MyScrollView.MyPageChangedListener() {
            @Override
            public void moveToDest(int currId) {
                RadioButton rbt = (RadioButton) radioGroup.getChildAt(currId);
                rbt.setChecked(true);
            }
        });

        radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                msv.moveToDest(checkedId);

            }
        });


    }


}
